<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link href="https://cdn.staticfile.org/bootstrap/4.6.1/css/bootstrap.min.css" rel="stylesheet">

    <link href="/css/common.css?v=2" rel="stylesheet">

    <title>Data Life</title>
</head>
<body>
<div class="container" id="app-main" v-cloak>
    <div class="row" style="margin-top: 10%">
        <div class="col-12">
            <h1>Data Life</h1>
            <form>
                <div class="form-group">
                    <label>Email address</label>
                    <input type="email" class="form-control" v-model="email">
                </div>
                <div class="form-group">
                    <label>Password</label>
                    <input type="password" class="form-control" v-model="password">
                </div>
                <a href="#" class="btn btn-primary" @click="login">Submit</a>
            </form>
        </div>
    </div>
</div>

<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.slim.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.6.1/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.js"></script>
<script src="https://cdn.staticfile.org/axios/0.26.0/axios.min.js"></script>

<script src="https://cdn.staticfile.org/axios/0.26.0/axios.min.js"></script>

<script src="/js/env.js?v=1"></script>
<script src="/js/common.js?v=2"></script>
<script>
    let vm = initVueApp();

    function initVueApp() {
        return new Vue({
            el: '#app-main',
            data: {
                email: '',
                password: ''
            },
            methods: {
                login: function () {
                    axios.post(env.apiPrefix + '/users/login', {email: vm.email, password: vm.password})
                        .then(function (response) {
                            if (response.data.code) {
                                return;
                            }
                            localStorage.setItem("token", response.data.data.token);

                            let from = getParam("from");
                            if (from == null) {
                                from = generateUrl("/moment/index.html", {});
                            } else {
                                from = generateUrl(from, {}, "-");
                            }

                            window.location.href = from;
                        });
                }
            }
        });
    }
</script>
</body>
</html>
